import CryptoJS from '@/common/aliyun_oss/crypto-js.js'
const key = CryptoJS.enc.Utf8.parse("wxkjasdasdasdasdasd123.."); //十六位十六进制数作为密钥
const iv = CryptoJS.enc.Utf8.parse("wxkjasdasdasdasdasd123.."); //十六位十六进制数作为密钥偏移量

//加密方法
export function Encrypt(word) {
	let srcs = CryptoJS.enc.Utf8.parse(word);
	let encrypted = CryptoJS.AES.encrypt(srcs, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.ciphertext.toString().toUpperCase();
}

//解密
export function Decrypt(str) {
	// str = (str + '').replace(/\n*$/g, '').replace(/\n/g, '').replace(/ /g, ''); //增加这一行，将换行符替换为空
	let base64 = CryptoJS.enc.Base64.parse(str);
	let src = CryptoJS.enc.Base64.stringify(base64);
	var decrypt = CryptoJS.AES.decrypt(src, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.ZeroPadding
	});
	// return decrypt.toString(CryptoJS.enc.Utf8);
	return decrypt.toString(CryptoJS.enc.Utf8).replace(/{/g, "").replace(/}/g, "").replace(/"/g, "");
}
export function Decrypt2(word) {
	word = (word + '').replace(/\n*$/g, '').replace(/\n/g, '').replace(/ /g, ''); //增加这一行，将换行符替换为空
	var decrypt = CryptoJS.DES.decrypt(word, key, {
		// iv: iv,
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	return decrypt.toString(CryptoJS.enc.Utf8);
}
